package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import io.renren.common.utils.ShiroUtils;
import io.renren.modules.generator.entity.WebRotationEntity;
import io.renren.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.WebPartnerEntity;
import io.renren.modules.generator.service.WebPartnerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 合作伙伴表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-11-24 12:56:48
 */
@RestController
@RequestMapping("generator/webpartner")
@Api(value = "合作伙伴",tags = {"合作伙伴"})
public class WebPartnerController {
    @Autowired
    private WebPartnerService webPartnerService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:webpartner:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = webPartnerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{partnerId}")
    @RequiresPermissions("generator:webpartner:info")
    public R info(@PathVariable("partnerId") Integer partnerId){
		WebPartnerEntity webPartner = webPartnerService.getById(partnerId);

        return R.ok().put("webPartner", webPartner);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:webpartner:save")
    public R save(@RequestBody WebPartnerEntity webPartner){
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        Long userId = userEntity.getUserId();
        webPartner.setCreateUser(Math.toIntExact(userId));
        webPartner.setCreateTime(new Date());
//        webPartner.setUpdateTime(new Date());
		    webPartnerService.save(webPartner);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:webpartner:update")
    public R update(@RequestBody WebPartnerEntity webPartner){
		webPartnerService.updateById(webPartner);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:webpartner:delete")
    public R delete(@RequestBody Integer[] partnerIds){
		webPartnerService.removeByIds(Arrays.asList(partnerIds));

        return R.ok();
    }

}
